package bim.controller;
//package com.haha.controller;
//
//import com.haha.entity.User;
//import com.haha.service.UserService;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//
//import java.util.Date;
//import java.util.List;
//
//@Controller
//public class UserController {
//
//    @Autowired
//    private UserService userService;
//
//    @RequestMapping(value = "/", method = RequestMethod.GET)
//    public String showUserForm(Model model) {
//        model.addAttribute("user",new User());
//        return "index";
//    }
//    
//    /**
//     * <p>Method ：showUserFormFake
//     * <p>Description : 请求路径相同但HTTP方法不同，可以采用不同的方法处理
//     * @param model
//     * @return 
//     * @author  gulixing@msn.com
//     * @version 1.0.0
//     */
//    @RequestMapping(value = "/", method = RequestMethod.POST)
//    public String showUserFormFake(Model model) {
//    	model.addAttribute("user",new User());
//    	return "index";
//    }
//
//    @RequestMapping(value = "/create", method = RequestMethod.POST)
//    public String saveUser( Model model, User user) {
//        User existing = userService.findByUserName(user.getUserName());
//        if (existing != null) {
//            model.addAttribute("status", "exist");
//            return "index";
//        }
//        user.setCreatedOn(new Date());
//        userService.saveUser(user);
//        model.addAttribute("saved", "success");
//        return "index";
//    }
//
//    @RequestMapping(value = "/search", method = RequestMethod.POST)
//    public String searchUser(Model model, User user) {
//        List<User> users = userService.findUsers(user.getUserName());
//        model.addAttribute("users", users);
//        model.addAttribute("search", true);
//        return "index";
//    }
//
//    /**
//     * <p>Method ：updateUser
//     * <p>Description : 进入修改页面
//     * @param model
//     * @param userName
//     * @return 
//     * @author  gulixing@msn.com
//     * @version 1.0.0
//     */
//    @RequestMapping(value = "/edit/{userName}", method = RequestMethod.GET)
//    public String updateUser(Model model, @PathVariable String userName) {
//        User user = userService.findByUserName(userName);
//        model.addAttribute("user", user);
//        return "update";
//    }
//
//    /**
//     * <p>Method ：updateUser
//     * <p>Description : 执行修改请求
//     * @param model
//     * @param user
//     * @return 
//     * @author  gulixing@msn.com
//     * @version 1.0.0
//     */
//    @RequestMapping(value = "/update", method = RequestMethod.POST)
//    public String updateUser( Model model, User user) {
//        userService.updateUser(user);
//        model.addAttribute("saved", "success");
//        return "update";
//    }
//    @RequestMapping(value = "/delete/{userName}", method = RequestMethod.GET)
//    public String deleteUser(Model model, @PathVariable String userName) {
//        userService.deleteUser(userName);
//        model.addAttribute("deleted", "success");
//        model.addAttribute("user", new User());
//        return "index";
//    }
//
//}
